package com.tanhua.server.controller;

import com.tanhua.domain.mongo.Movement;
import com.tanhua.server.service.MovementService;
import com.tanhua.server.service.RocketMqService;
import com.tanhua.server.service.SettingsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/movements")
public class MovementController {



    @Autowired
    private MovementService movementService;

    @Autowired
    private RocketMqService rocketMqService;

    @PostMapping(name = "发布动态")
    public ResponseEntity saveMovements( Movement movement , MultipartFile[] imageContent) throws Exception{

        return movementService.saveMovements(movement,imageContent);

    }
    @GetMapping(name = "查询好友动态")
    public ResponseEntity queryFriendMovements(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{

        return movementService.queryFriendMovements(page,pagesize);

    }

    @GetMapping(value = "/recommend",name = "查询推荐动态")
    public ResponseEntity queryRecommendMovements(@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{

        return movementService.queryRecommendMovements(page,pagesize);

    }
    @GetMapping(value = "/all",name = "查询指定用户的动态")
    public ResponseEntity queryMyselfMovements(Long userId,@RequestParam(defaultValue = "1") Integer page,
                                               @RequestParam(defaultValue = "10")Integer pagesize) throws Exception{

        return movementService.queryMyselfMovements(userId,page,pagesize);

    }

    @GetMapping(value = "/{id}/like",name = "对圈子点赞")
    public ResponseEntity like(@PathVariable("id") String movementId) throws Exception{

        rocketMqService.sendMsg(movementId,2);
        return movementService.like(movementId);

    }

    @GetMapping(value = "/{id}/dislike",name = "对圈子取消点赞")
    public ResponseEntity dislike(@PathVariable("id") String movementId) throws Exception{

        rocketMqService.sendMsg(movementId,5);
        return movementService.dislike(movementId);

    }

    @GetMapping(value = "/{id}/love",name = "对圈子喜欢")
    public ResponseEntity love(@PathVariable("id") String movementId) throws Exception{

        rocketMqService.sendMsg(movementId,3);
        return movementService.love(movementId);

    }

    @GetMapping(value = "/{id}/unlove",name = "对圈子取消喜欢")
    public ResponseEntity unlove(@PathVariable("id") String movementId) throws Exception{

        rocketMqService.sendMsg(movementId,6);
        return movementService.unlove(movementId);

    }

    @GetMapping(value = "/{id}",name = "查询指定圈子详情")
    public ResponseEntity queryMovementById(@PathVariable("id") String movementId) throws Exception{


        rocketMqService.sendMsg(movementId,1);
        return movementService.queryMovementById(movementId);

    }
    @GetMapping(value = "/visitors",name = "谁看过我")
    public ResponseEntity queryVisitors( ) throws Exception{

        return movementService.queryVisitors(4);

    }




}
